/**
 * Controller class for the Customer Container
 */

package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;


public class CustomerCTR
{
   private CustomerContainer cctr;
   
   /**
     * Constructor for objects of class CustomerCTR
     */
   public CustomerCTR()
    {
       cctr = CustomerContainer.getSingelton();
    }
    
    /**
     * Finds the the entry in array via the customers phonenumber.
     * 
     * @param phone customers phonenumber to be used in search.
     */
    public Customer getCustomer(String phoneNo)
    {
        Customer customer = cctr.findCustomer(phoneNo);
        return customer;
    }
    
    /**
     * Creating a new entry in the customer container.
     * 
     * @param first name sets the first name for the entry
     * @param last name sets the last name for the entry
     * @param address sets the address for the enty
     * @param zipcode sets the zip code for the entry
     * @param city sets the city for the entry
     * @param phoneNo sets the phonenumber for the entry
     */
    public void createCustomer(String firstName, String lastName, String address, String zipcode, String city, String phoneNo)
    {
        Customer customer = new Customer(firstName, lastName, address, zipcode, city, phoneNo);
        cctr.addCustomer(customer);
    }
    
    /**
     * Deleting a customer with the use of there phonenumber.
     * 
     * @param phone the customers phonenumber to be used in deleting there information
     */
    public boolean deleteCustomer(String phone)
    {
        return cctr.deleteCustomer(phone);
    }
    
    /**
     * Lists all customers in array.
     */
    public ArrayList<Customer> listAllCustomers()
    {
        return cctr.listAllCustomer();
    }
    
    /**
     * Updating personal information.
     * 
     * @param choise selecting wich part to edit
     * @param newData the data to replace in array
     */
    public void updateCustomerData(Customer customer, int choice, String newData)
    {
        if (choice == 1)
        {
            customer.setPersonFirstName(newData);
        } 
        else if (choice == 2)
        {
            customer.setPersonLastName(newData);
        }
        else if (choice == 3)
        {
            customer.setAddress(newData);
        }
        else if (choice == 4)
        {
            customer.setZipCode(newData);
        }
        else if (choice == 5)
        {
            customer.setCity(newData);
        }
        else if (choice == 6)
        {
            customer.setPhoneNo(newData);
        }
    }
    
    /**
     * Editing personal information.
     * 
     * @param choise selecting wich part to edit
     * @param newData the data to replace in array
     */
    public void editCustomerData(Customer customer, int choice, String newData)
    {
        if(choice == 1)
        {
            customer.setPersonFirstName(newData);
        }
        else if(choice == 2)
        {
            customer.setPersonLastName(newData);
        }
        else if(choice == 3)
        {
            customer.setAddress(newData);
        }
        else if(choice == 4)
        {
            customer.setZipCode(newData);
        }
        else if(choice == 5)
        {
            customer.setCity(newData);
        }
        else if(choice == 6)
        {
            customer.setPhoneNo(newData);
        }
    }

    
}
